// 一、对象接口类型
interface Some {
  id: number;
  // 让id成为只读属性
  //   readonly id: number;
  name: string;
  // 可选属性
  message?: string;
  //   [propName: string]: any;
}

interface Res {
  data: Some[];
}

function render(target: Res) {
  target.data.forEach((value) => {
    console.log(value.id + "," + value.name);
    // value.id++;
  });
}

var information = {
  data: [
    { id: 1001, name: "max", message: "success" },
    { id: 1002, name: "star" },
  ],
};
// 方式1
render(information);
// 方式2
render({
  data: [
    { id: 1001, name: "max", message: "success" },
    { id: 1002, name: "star" },
  ],
} as Res);
// 方式3
render(<Res>{
  data: [
    { id: 1001, name: "max", message: "success" },
    { id: 1002, name: "star" },
  ],
});

// 二、函数类型接口
// let fun: (x: number, y: number) => number;
// fun = (x, y) => x + y;

// type func = (x: number, y: number) => number;
// let fn: func = (x, y) => x + y;

// interface Func {
//   (x: number, y: number): number;
// }
// let fn: Func = (x, y) => x + y;

// 混合类型接口
interface Func {
  (): void;
  version: string;
  isObject(x: object): boolean;
}

let fn: Func = (() => {}) as Func;
fn.version = "v1.0.0";
fn.isObject = (x) => {
  return typeof x === "object";
};
